#include "AllStockCodeCmd.h"
#include <ace/CDR_Stream.h>
#include "MessageBlockManager.h"
#include <string>
#include "stockdrv.h"
#include "CommandId.h"

CAllStockCodeCmd::CAllStockCodeCmd(void)
{
	m_pServerObject = NULL;
}

CAllStockCodeCmd::~CAllStockCodeCmd(void)
{
}

int CAllStockCodeCmd::DoMessage( IPacketData* pMessage )
{
	ACE_Message_Block* pmb = pMessage->GetPacketData();
	uint16 u2Command;
	uint32 nCount;
	App_MessageBlockManager::instance()->Read<_DEFAULT_>(*pmb, u2Command);
	App_MessageBlockManager::instance()->Read<_DEFAULT_>(*pmb, nCount);
	
	std::string strCode;
	
	for (int i = 0; i < nCount; ++i)
	{
		App_MessageBlockManager::instance()->Read<_VCHARS_>(*pmb, strCode);

		OUR_DEBUG((LM_INFO, "[CAllStockCodeCmd::DoMessage] StockCode %s.\n", strCode.c_str()));
	uint16 u2Market = SH_MARKET_EX;
	if (strCode.find("SH") != std::string::npos)
	{
		u2Market = SH_MARKET_EX;
	}else if (strCode.find("SZ") != std::string::npos)
	{
		u2Market = SZ_MARKET_EX;
	}else
	{
		return false;
	}

	strCode = strCode.substr(2);
	uint16 u2CommandRegist = COMMAND_REGISTERREPORT;
	ACE_Message_Block *pMb = App_MessageBlockManager::instance()->Create(sizeof(uint16) + sizeof(uint16) + sizeof(uint8) + strCode.length());
	App_MessageBlockManager::instance()->Write<_DEFAULT_>(*pMb, u2CommandRegist);
	App_MessageBlockManager::instance()->Write<_DEFAULT_>(*pMb, u2Market);
	App_MessageBlockManager::instance()->Write<_VCHARS_>(*pMb, strCode);
	m_pServerObject->GetClientManager()->PostMessage(pMessage->GetRemotAdr(), pMb);
	pMb->release();


	}
	
	return 0;
}
